import os.path
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

import click

from dp_analysis.db.connection import Mysql


@click.command()
@click.option("--db", default=0, help="请选择使用的数据库")
@click.option("--region", default=1, help="获取所有地区")
@click.option("--cuisine", default=1, help="获取所有菜系")
def main(db, region, cuisine):
    if region == cuisine == 0:
        raise Exception("请选择要获取的对象")

    with Mysql("dp", db) as mysql:
        connection = mysql.engine.connect()

        region_list = list()
        if region:
            for (reg, ) in connection.execute("SELECT DISTINCT region from shop_info;").fetchall():
                region_list.append(reg)
            print(f"所有地区如下：{region_list}")

        if cuisine:
            for region in region_list:
                cuisine_list = list()
                for (cui, ) in connection.execute("SELECT "
                                                  "DISTINCT category "
                                                  "from shop_info "
                                                  "WHERE category NOT IN ('评论', '热门', '口味', '环境', '服务') "
                                                  "AND region={!r};".format(region)).fetchall():
                    cuisine_list.append(cui)
                print(f"{region}地区所有菜系如下：{cuisine_list}")


if __name__ == '__main__':
    main()
